package com.cat.enumerate;

import java.util.Arrays;

/**
*   @description https://leetcode.cn/problems/maximum-strength-of-a-group/description/?envType=problem-list-v2&envId=enumeration
*   @author 曲大人的喵
*   @create 2025/9/21 18:31
*   @since JDK17
*/

public class Solution11 {
    long ans;
    void dfs(int[] nums, int i, long sum) {
        if (i == nums.length) {
            ans = Math.max(ans, sum);
            return;
        }

        dfs(nums, i + 1, sum * nums[i]);
        dfs(nums, i + 1, sum);
    }

    public long maxStrength(int[] nums) {
        dfs(nums, 0, 1);
        return ans == 1 ? Arrays.stream(nums).max().getAsInt() : ans;
    }
}
